#comments-start
Copyright (c) <2011>, <John Seekins>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#comments-end
Dim $driveMapErrors[6]
$driveMapErrors[0] = "Undefined or Other"
$driveMapErrors[1] = "Access to the remote share was denied"
$driveMapErrors[2] = "The device is already assigned"
$driveMapErrors[3] = "Invalid device name"
$driveMapErrors[4] = "Invalid remote share"
$driveMapErrors[5] = "Invalid password"

Func CopyFiles($ImageName, $InstallLoc, $DriverLoc, $cpDrivers, $cpInstall, $cpDirectory)
	If StringCompare(StringRight($cpDirectory, 1), "\") = 0 Then StringTrimRight($cpDirectory, 1)

	If $cpDrivers = $GUI_CHECKED Then $DriverLoc = FileSelectFolder("Select Driver Folder", $DriverLoc)

	If $cpInstall = $GUI_CHECKED Then $DestDrive = InputBox("Destination?", "Input the destination drive to copy Program files to:")

	ProgressOn("Copying Image and other files...", "", "", -1, -1, 18)
	ProgressSet(2, "Copying Image File " & $ImageName & ". (This takes time...)")
	FileCopy($ImageName, $cpDirectory, 1)
	If $cpDrivers = $GUI_CHECKED Then
		ProgressSet(65, "Copying Drivers...")
		DirCopy($DriverLoc, $cpDirectory & "\Drivers", 1)
	EndIf
	If $cpInstall = $GUI_CHECKED Then
		ProgressSet(75, "Copying Install Files...")
		DirCopy($InstallLoc, $cpDirectory & "\BIN", 1)
	EndIf
	ProgressSet(100, "Done!", "Completed File Copy")
	Sleep(3000)
	ProgressOff()
EndFunc   ;==>getCopyInstructions

Func DoMapping($mapLetter, $mapShare, $mapUser = "", $mapPassword = "")

	DriveMapDel($mapLetter)
	If ($mapUser = $mapPassword) AND ($mapPassword = "") Then
		$res = DriveMapAdd($mapLetter, $mapShare)
	Else
		$res = DriveMapAdd($mapLetter, $mapShare, -1, $mapUser, $mapPassword)
	EndIf

	If $res <> 1 Then
		SplashOff()
		MsgBox(16, "Drive Mapping", "Error mapping drive!" & @LF & "Error Code: " & $driveMapErrors[@error])
	EndIf
	Return $res
EndFunc   ;==>DoMapping

Func NetworkInit($serverName, $ImageLoc, $InstallLoc, $DriverLoc)
	$sysprepPath = $serverName & "\images"
	$installPath = $serverName & "\install"
	$driversPath = $serverName & "\drivers"
	$sysprepDrive = StringLeft($ImageLoc, 2)
	$installDrive = StringLeft($InstallLoc, 2)
	$driverDrive = StringLeft($DriverLoc, 2)

	DriveMapDel($sysprepDrive)
	DriveMapDel($installDrive)
	DriveMapDel($driverDrive)

	ProgressOn("Network Initialization", "", "", -1, 0, 16)
	ProgressSet(3, "Beginning Basic Network Init")
	$ret = RunWait(@ComSpec & ' /c WPEUTIL INITIALIZENETWORK"', @WorkingDir, @SW_HIDE)
	If $ret <> 0 Then
		SplashTextOn("Failed!", "Basic network initialization failed...", 400, 200, -1, -1, 32, "Tahoma", 16, 500)
		Sleep(3000)
		SplashOff()
		ProgressSet(100, "Error", "Failed Network Initialization!")
		Sleep(3000)
		ProgressOff()
		Return 0
	EndIf
	ProgressSet(55, "Mapping Network Drives")

	;RAM Computers-specific
	$ret = DoMapping($sysprepDrive, $sysprepPath)
	If $ret <> 1 Then
		ProgressSet(100, "Error", "Failed Network Initialization!")
		Sleep(3000)
		ProgressOff()
		Return 0
	EndIf
	ProgressSet(70, "Mapping Network Drives")
	$ret = DoMapping($installDrive, $installPath)
	If $ret <> 1 Then
		ProgressSet(100, "Error", "Failed Network Initialization!")
		Sleep(3000)
		ProgressOff()
		Return 0
	EndIf
	ProgressSet(90, "Mapping Network Drives")
	$ret = DoMapping($driverDrive, $driversPath)
	If $ret <> 1 Then
		ProgressSet(100, "Error", "Failed Network Initialization!")
		Sleep(3000)
		ProgressOff()
		Return 0
	EndIf
	;end RAM Computers-specific

	ProgressSet(100, "Done", "Completed Network Initialization!")
	Sleep(3000)
	ProgressOff()
	Return 1
EndFunc   ;==>NetworkInit
